import type {Graph} from "@/business/entity/graph/graph.entity";
import {ProxyGraphService} from "@/business/proxy/graph.proxy";
import {DrawAbstractFactory} from "@/business/factory/draw.abstract";
import type {Panel} from "@/business/entity/panel/panel.entity";
import type {GraphService} from "@/business/interface/graph.interface";

/**
 *  图形绘制策略工厂实现类
 * @author JiangXincan
 * @date 2023/01/29 13:56
 */
export class DrawFactory extends DrawAbstractFactory {

    // 绘图上下文
    private readonly _ctx: CanvasRenderingContext2D;

    constructor(panel: Panel) {
        super(panel);
        this._ctx = this.createCanvas2DContext();
    }

    /**
     * 绘图开始
     * @param graph 绘图对象
     */
    public draw(graph: Graph) {
        const proxyGraphService: ProxyGraphService<GraphService> = new ProxyGraphService<GraphService>(this._ctx,graph.id);
        proxyGraphService.graphDraw(graph);
    }

}